package com.gitee.wsl.ext.number

import com.gitee.wsl.ext.bitcode.unsigned
import com.gitee.wsl.mathematics.number.approx
import com.gitee.wsl.mathematics.number.compareTo


infix fun Int.compareUnsigned(other: Int): Int = this.unsigned compareTo other.unsigned

//infix fun Long.compareUnsigned(other: Long): Int = this.toULong() compareTo other.toULong()

infix fun <T:Number> Iterable<T>.approx(u: Iterable<T>): Boolean = zip(u).all { it.first approx  it.second }

infix fun<T:Number> Iterable<T>.allLessThan(f: Number): Boolean = all { it < f }
infix fun<T:Number> Iterable<T>.anyLessThan(f: Number): Boolean = any { it > f }
infix fun<T:Number> Iterable<T>.lessThan(f: Number): List<T> = filter { it < f }

infix fun<T:Number> Iterable<T>.allLessThanEqual(f: Number): Boolean = all{ it<=f }
infix fun<T:Number> Iterable<T>.anyLessThanEqual(f: Float): Boolean = any { it <=f }
infix fun<T:Number> Iterable<T>.lessThanEqual(f: Float):  List<T> = filter { it <= f }

fun<T:Number> Iterable<T>.allEqual(f: Number): Boolean = all{ it approx f }
fun<T:Number> Iterable<T>.anyEqual(f: Number): Boolean = any{ it approx f }
fun<T:Number> Iterable<T>.equal(f: Number):  List<T> = filter { it approx f }

fun<T:Number> Iterable<T>.allNotEqual(f: Number): Boolean = !allEqual(f)
fun<T:Number> Iterable<T>.anyNotEqual(f:Number): Boolean = any{ !(it approx f) }
fun<T:Number> Iterable<T>.notEqual(f:Number):  List<T> = filter { !(it approx f) }

infix fun<T:Number> Iterable<T>.allGreaterThan(f: Number): Boolean = all{ it > f }
infix fun<T:Number> Iterable<T>.anyGreaterThan(f: Number): Boolean = any{ it > f }
infix fun<T:Number> Iterable<T>.greaterThan(f: Number):  List<T> = filter { it > f }

infix fun<T:Number> Iterable<T>.allGreaterThanEqual(f: Number): Boolean = all{ it >= f }
infix fun<T:Number> Iterable<T>.anyGreaterThanEqual(f: Number): Boolean = any{ it >= f }
infix fun<T:Number> Iterable<T>.greaterThanEqual(f: Number): List<T> = filter { it >= f }





